Skip to content

perf build class, better show_source#43

Merged
ermolaev merged 1 commit intomasterfrom
perf
Dec 16, 2024
Merged

perf build class, better show_source#43
ermolaev merged 1 commit intomasterfrom
perf

Conversation

@ermolaev
Copy link
Contributor

class B
end

Benchmark.ips do |x|
  x.report("class_eval")         { B.class_eval("def a? = 1") }
  x.report("define_method str")  { B.define_method("#{:a}?") { 1 } }
  x.report("define_method sym")  { B.define_method(:"#{:a}?") { 1 } }
  x.compare!
end;

# Comparison:
#    define_method sym:  2324533.3 i/s
#    define_method str:  2286626.9 i/s - same-ish: difference falls within error
#           class_eval:   257038.4 i/s - 9.04x  slower

@ermolaev ermolaev merged commit 30df8f7 into master Dec 16, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants